// miniprogram/pages/org/org.js
import {OrgModel} from '../../model/org'
import {IndexModel} from '../../model/index'
import {UserModel} from '../../model/user'
import {isRegister} from '../../utils/utils'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activityList: [1, 2],
    // 风采展示
    list2: [],
    currentIndex: -1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadOrgList()
  },
  loadOrgList(){
    IndexModel.dictList('sys_activity_type').then((res) => {
      console.log(res)
      if(res && res.code == 200) {
        this.setData({
          activityList: res.rows
        })
      }else {
        console.log(res)
      }
    }).catch(e => {
      console.log(e)
    })
  },
  jump(e){
    console.log(e.detail.id)
    if(e.detail.id === 2){
      wx.navigateTo({
        url: `./index?type=1`,
      })
    }else {
      wx.navigateTo({
        url: `./index?activityType=${e.detail.id+1}`,
      })
    }
    
  },
  loadBeautyList() {
    OrgModel.beautyList().then((res) => {
      if (res && res.code == 200) {
        console.log('list2', res)
        this.setData({
          list2: res.rows
        })
      } else {
        console.log(res)
      }
    }).catch(e => {
      console.log(e)
    })
  },
  dig(e) {
    console.log('点赞', e)
    let beautyId = e.currentTarget.dataset.id
    isRegister()
    let data = {
      beautyId: beautyId
    }
    UserModel.digBeauty(data).then((res) => {
      if (res && res.code == 200) {
        console.log(res)
        // this.data.list2[beautyId - 1].isDig = this.data.list2[beautyId - 1].isDig ^ 1
        // this.setData({
        //   list2: this.data.list2
        // })
        this.loadBeautyList()
        // console.log('list2', this.data.list2)
      } else {
        console.log(res)
      }
    }).catch(e => {
      console.log(e)
    })
  },
  showMore(e) {
    let index = e.currentTarget.dataset.index
    this.setData({
      currentIndex: index
    })
  },

  showLess(e) {
    let index = -1
    this.setData({
      currentIndex: index
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.data.list2 = []
    this.loadBeautyList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})